package com.handinfo.android.download;

import java.io.File;



import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.resource.IORWFile;
import com.handinfo.android.utils.Tools;

import android.app.Activity;
//import android.app.DownloadManager;
import android.net.Uri;
import android.os.Environment;

public class DWDownloadManager
{
//	public static final String APK_NAME = "xycs_lite.apk";
//	public static String s_savefold = "mnt/sdcard/Download/";
//	public static String s_url_download = "http://192.2.9.191:8080/downloadPro/apps/xycs_lite.apk";

//	private DownloadManager m_downloadManager;
	private long m_download_id = -2;

	public DWDownloadManager()
	{
//		if (IORWFile.getSDCardDir() == null) {
//			s_savefold = "data/data/com.handinfo.android/files/";
//		}
//		m_downloadManager = (DownloadManager) DWGameManager.getInstance().getCurrentActivity().getSystemService(
//				Activity.DOWNLOAD_SERVICE);
//		Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
	}

	public void startDownload(String url)
	{
//		if (m_downloadManager != null) {
//			Uri uri = Uri.parse(url);
//
//			File file = new File(s_savefold + APK_NAME);
//			if (file.exists()) {
//				file.delete();
//			}
//
//			DownloadManager.Request request = new DownloadManager.Request(uri);
//			request.setTitle("仙缘传说");
//			request.setDescription("下载最新的仙缘传说");
//			request.setDestinationUri(Uri.parse(s_savefold + APK_NAME));
//			request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, APK_NAME);
//			request.setVisibleInDownloadsUi(true);
//			request.setShowRunningNotification(true);
//			request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
//					| DownloadManager.Request.NETWORK_WIFI);
//
//			m_download_id = m_downloadManager.enqueue(request);
//			Tools.debugPrintln("请求下载客户端包id ： " + m_download_id);
//		}
		/**
		 * kenny2012年10月19日更改下载方式
		 */
		final String urls=url;
		
		DWGameManager.getInstance().getCurrentActivity().mHandler.post(new Runnable() {
			
			public void run() {

					 Update up = new Update(DWGameManager.getInstance().getCurrentActivity(), urls);	
			
			}
		});
		
		
	}
	
	public long getDownloadId()
	{
		return m_download_id;
	}
}
